package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.Excel;
import com.ccp.dev.qbdms.dao.WQbdSubStandardClauseDao;
import com.ccp.dev.qbdms.model.WQbdSubStandardClause;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * 子标准条款 信息操作服务类
 *
 * @author 王明亮
 * @date 2020-07-23 21:03:44
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WQbdSubStandardClauseService extends BaseService<WQbdSubStandardClause> {

    @Resource
    private WQbdSubStandardClauseDao dao;

    public HSSFWorkbook exportExcel(Excel excel, QueryFilter queryFilter) {
        List<WQbdSubStandardClause> dataList = this.dao.queryAll(queryFilter);
        int startRow = 1;
        //给每一个单元格赋值
        for (WQbdSubStandardClause data : dataList) {
            excel.cell(startRow, 0).value(data.getId());
            //excel.cell(startRow, 1).value(data.getMc());
            //可在赋值时，根据需求进行格式化
            //excel.cell(startRow, 2).value(DateFormatUtil.formatDate(data.getRq()));
            //excel.cell(startRow, 3).value(data.getSj());
            //excel.cell(startRow, 4).value(data.getTenantId());
            startRow++;
        }
        return excel.getWorkBook();
    }

    /**
     * 获取最大排序号
     *
     * @return
     */
    public int getMaxSortId() {
        return dao.getMaxSortId();
    }

    /**
     * 根据标准条款id获取子标准条款
     *
     * @param standardClauseId
     * @return
     */
    public List<WQbdSubStandardClause> getByStandardClauseId(String standardClauseId) {
        return dao.getByStandardClauseId(standardClauseId);
    }

    /**
     * 根据依据标准编码和标准条款名称获取子标准条款
     *
     * @param accordingStandard
     * @param standardClause
     * @return
     */
    public List<WQbdSubStandardClause> getByAccordingStandardAndStandardClause(String accordingStandard, String standardClause) {
        return dao.getByAccordingStandardAndStandardClause(accordingStandard, standardClause);
    }
}
